<?php
//声明CODE，获取小程序传过来的CODE
$code = $_GET["code"];
//配置appid
$appid = "wxf71bd435365c2432";
//配置appscret
$secret = "625aaf57c5d562fda7d5af2a8b082b76";
//api接口
$api = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
$info = file_get_contents($api); //发送HTTPs请求并获取返回的数据，推荐使用curl
$json = json_decode($info); //对json数据解码
$arr = get_object_vars($json);
$openid = $arr['openid'];
echo $openid;

?>
